<template>
	<view class="u-card-wrap">
		<!-- <u-navbar title="我的课表" :autoBack="true" safeAreaInsetTop fixed placeholder /> -->
		<view class="u-demo-block__content">
			<ren-calendar ref='ren' :markDays='markDays' @onDayClick='onDayClick' @onChangeMonth="changeMonth"></ren-calendar>
			
			<uni-card :title="curDatePretty+'课表'"  :extra="displayExtra()"
				padding="0">
				<view slot="actions"  style="font-size: 28rpx;" v-for="(item,index) in lessonList" :key="index">
					<u-row>
						<u-col span="6">
							<view class="view-height" style="color: #4d7df9;">
								<u-row>
									<u-col span="6">
										老师: {{item.teacherName}} {{item.classroom ? '教室:' + item.classroom : ''}}
									</u-col>
									<u-col span="4">
										<view style="font-size:20rpx;margin-left:2px;">{{item.stateValue}}</view>
									</u-col>
								</u-row>
							</view>
							<view class="view-height">{{item.className}} {{item.courseName}}</view>
							<view class="view-height">{{item.startTime}} ~ {{item.endTime}}
							</view>
						</u-col>
						
						
						<u-col span="8"  offset="2">
							<u-grid>
								<u-grid-item>
									<view>
										到课&nbsp;&nbsp;{{item.studentSignNum || 0}}&nbsp;/&nbsp;{{item.studentNum || 0}}
									</view>
									<view style="margin-top: 20rpx;">
										<u-button type="primary"  size="small"
											@click="handleRollcall(item.id)" text="点  名"></u-button>
									</view>
								</u-grid-item>
							</u-grid>
						</u-col>
					</u-row>
				</view>
				<u-empty v-if="lessonList.length == 0" mode="list" text="本日无课"></u-empty>
			</uni-card>
		</view>
	</view>
</template>
<script>
	import RenCalendar from '@/components/ren-calendar/ren-calendar.vue'
	import request from '@/utils/request'
	
	export default {
		components: {
			RenCalendar
		},
		data() {
			return {
				curDate: '',
				curDatePretty: '',
				markDays: [],
				lessonList: []
			}
		},
		onReady() {
			let today = this.$refs.ren.getToday().date;
			this.curDate = today;
			this.curDatePretty = this.datePretty(today);
		},
		onShow() {
			this.$nextTick(() => {
				this.getLessons()
				this.lessonCountEveryDay()
			})
		},
		methods: {
			displayExtra() {
				return this.lessonList.length > 0 ? `今日${this.lessonList.length}节课` : '无课';
			},
			getLessons() {
				request({url:'/edu/lesson/pageForTeacher', data:{
					lessonDate: this.curDate
				}}).then(res => {
					if(!this.$common.handleResponseMsg(res)) return;
					this.lessonList = res.data.list
				});
			},
			lessonCountEveryDay() {
				request({url:'/edu/lesson/lessonCountEveryDay4Teacher', data:{
					lessonDate: this.curDate
				}}).then( res => {
					if(!this.$common.handleResponseMsg(res)) return;
					this.markDays = res.data || []
				});
			},
			handleRollcall(lessonId) {
				uni.navigateTo({ url : `/pages/lesson/rollcall?lessonId=${lessonId}` });
			},
			handleEvaluate(lessonId) {
				 this.$modal.showToast('模块建设中~')
				 return;
				uni.navigateTo({ url : `/pages/lesson/evaluate?lessonId=${lessonId}` });
			},
			onDayClick(data) {
				this.curDate = data.date;
				this.getLessons()
				this.curDatePretty = this.datePretty(data.date);
			},
			datePretty(date) {
				const weekDayZh = ['日', '一', '二', '三', '四', '五', '六']
				let day = new Date(date);
				return (day.getMonth() + 1) + "月" + day.getDate() + "日";
			},
			changeMonth(day) {
				this.curDate = day;
				this.getLessons()
				this.lessonCountEveryDay()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.view-height {
		line-height: 220%;
		height: 220%;
	}
</style>
